﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<#include "/views/ftl/base/manager_include.ftl">
<head>
<title>配置权限</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

   
	<script language="javascript" src="${basePath}js/jquery_treeview/jquery.treeview.js"></script>
	
	<link type="text/css" rel="stylesheet" href="${basePath}js/jquery_treeview/jquery.treeview.css" />

	<script type="text/javascript">
 		// 选择所有
    	function selectAll(checkedValue){
    		$("input[type=checkbox][name=resourceIdList]").attr("checked", checkedValue);
    	}
    	
    	function doChecked( liID, checkedValue ){
			// 当前点击的checkbox元素所在的li元素
    		var jLi = $("#" + liID);

    		// 选中所有的直属下级。（children()方法是筛选下一级，find()是筛选所有后代）
    		jLi.children("ul").find("input[type=checkbox]").attr("checked", checkedValue);
    		
    		// 选中或取消选中直属上级
    		if( checkedValue ){ // checkedValue是boolean型，表示是否选中了当前复选框
    			// 如果当前是选中，则选中所有的直属上级
				jLi.parents("li").children("input[type=checkbox]").attr("checked", checkedValue);
			}else{
				// 如果当前是取消选中，并且同级中没有被选中的项，则也取消上级的选中状态
				var jCheckedSibingCB = jLi.siblings("li").children("input[type=checkbox]:checked");
				if(jCheckedSibingCB.size() == 0){
					var jCheckboxInput = jLi.parent("ul").prev("label").prev("input[type=checkbox]");
					jCheckboxInput.attr("checked", checkedValue);
					
					// 递归操作每一层直属上级
					var jParentLi = jCheckboxInput.parent("li");
					if(jParentLi.size() > 0){
						doChecked(jParentLi.attr("id"), checkedValue);
					}
				}
			}
    	} 
    	
    	$(function(){
    		$("#tree").treeview();
    	var j='${resourceIdList}'.split(',');
    		
    	for(var i=0;i<j.length;i++){
    	 $('input[name="resourceIdList"]').each(function(){    
    	  if(($(this).val()==j[i]))     
	   {   
	   $(this).attr("checked",'true');  
	         
	   }     
      
    	 });
    	
    	}
    	
    	
    	});
    	
    	function save(){
  		  var ids="";
    	
    	  $('input[name="resourceIdList"]:checked').each(function(){
                var sfruit=$(this).val();
                ids+=sfruit+",";
                });
        if(ids==""){
        alert("请选择至少一个选项");
        return;
        }
		 $.ajax({ 
			url : "${basePath }manager/Authority_setAuthority",
			data : { 
				roleId : ${(role.id)?c},
				ids : ids
			}, 
			dataType :"JSON",
			cache : false, 
			type : "POST",
			success : function(dat){
				if(dat.code==1){
				alert(dat.msg);
				window.location.href="${basePath }manager/Role_roleList"; 
				}else if(dat.code==0){
					alert(dat.msg);
				} 	
			}
		});
    	}
    </script>
</head>
<body style="">
<#include "/views/ftl/base/head.ftl">
<div class="Main">
  <div class="dw">
<#include "/views/ftl/base/menu.ftl">
<#function a><#return "角色列表_List"></#function> 
<!-- 标题显示 -->
<div id="Title_bar" class="Rightbox fl">
 <!--导航-->
    <div class="Bread_crbs clear">
      <div class="Bread_crbs_img fl"></div>
      <div class="Bread_crbs_text fl">
      	<a href="javascript:void(0);"><span>权限设置</span></a>
      	<span class="fnt_famy">></span>
      	<a href="javascript:void(0);"><span>正在为【${role.name}】配置权限</span></a>
      </div>
    </div>

<!--显示表单内容-->
<div id=MainArea style="font-size:15px">
    <form action="">
 
        <!-- 表单内容显示 -->
        <div class="ItemBlockBorder">
            <div class="ItemBlock">
                <table cellpadding="0" cellspacing="0" class="table">
					<!--表头-->
					<thead>
						<tr align="LEFT" valign="MIDDLE" id="TableTitle">
							<td width="300px" style="padding-left: 7px;">
								<!-- 如果把全选元素的id指定为selectAll，并且有函数selectAll()，就会有错。因为有一种用法：可以直接用id引用元素 -->
								<input type="CHECKBOX" id="cbSelectAll" onClick="selectAll(this.checked)"/>
								<label for="cbSelectAll">全选</label>
							</td>
						</tr>
					</thead>
                   
			   		<!--显示数据列表-->
					<tbody id="TableData">
						<tr class="TableDetail1">
							<!-- 显示权限树 -->
							<td>
<ul id='tree'>
	<li id='li_999'>
	<input type="hidden" name="xx" value="xxxxxxxxx">
		<input type='checkbox' name='resourceIdList' id='cb_999' onclick='doChecked("li_999", this.checked)' value=''/>
		<label for='cb_999'><span class='folder' id='45'>系统管理</span></label>
		<ul>
  		<#if (list??)> 
         <#if ((list?size)>0)>
          <#list list as bean>
				<li id='li_${(bean.id)?c}'>
				<input type='checkbox' name='resourceIdList' id='cb_${(bean.id)?c}' value='${(bean.id)?c}' onclick='doChecked("li_${(bean.id)?c}", this.checked)'/>
				<label for='cb_${(bean.id)?c}'><span class='folder' id='${(bean.id)?c}'>${(bean.name)!''}</span></label>
				<ul>
		     	 <#if (bean.children??)> 
		         <#if ((bean.children?size)>0)>
		          <#list bean.children as cbean>
						<li id='li_128'>
						<input type='checkbox' name='resourceIdList' value='${(cbean.id)?c}' id='cb_${(cbean.id)?c}' onclick='doChecked("li_${(cbean.id)?c}", this.checked)'/>
						<label for='cb_li_${(cbean.id)?c}'><span class='folder' id='li_${(cbean.id)?c}'>${(cbean.name)!''}</span></label>
						</li>
					 </#list >
			          </#if>
			          </#if>
				</ul>
			</li>
			 </#list >
          	</#if>
         	 </#if>
			
		</ul>
	</li>

	
</ul>
</td>
						</tr>
					</tbody>
                </table>
            </div>
        </div>
        <br>
        <!-- 表单操作 -->
        <div id="InputDetailBar" class="tbl_btn">
            <a href="javascript:save();"> <span id="editor">提交</span></a>
            <a href="javascript:history.go(-1);"> <span id="editor">返回</span></a>
        </div>
    </form>
</div>
      <br>

  </div>
</div>
</body>
</html>


